package com.utils;

import java.nio.charset.StandardCharsets;

/**
 * http协议mock工具类
 *
 * @author liangzj
 * @date 2021/3/28 0:08
 */
public class HttpProtocolMocker {

    public static String mockHttpHeader200(long contentLength) {
        return "HTTP/1.1 200 OK \n"
                + "Content-Type: text/html \n"
                + "Content-Length: " + contentLength + "\n"
                + "\r\n";
    }

    public static String mockHttpHeader404() {
        String str404 = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 NOT Found \n"
                + "Content-Type: text/html \n"
                + "Content-Length: " + str404.getBytes(StandardCharsets.UTF_8).length + "\n"
                + "\r\n"
                + str404;
    }

}
